//package edu.washington.cs.workflow.analysis.guistructure;
//
//import java.util.Collection;
//import java.util.LinkedList;
//
//import org.uispec4j.Panel;
//import org.uispec4j.UIComponent;
//import org.uispec4j.UISpec4J;
//import org.uispec4j.UISpecTestCase;
//import org.uispec4j.interception.MainClassAdapter;
//
//import edu.washington.cs.workflow.analysis.guistructure.uievents.UIEvent;
//import edu.washington.cs.workflow.util.Utils;
//
///**
// * Given a window to do all... check if a window is still there?
// * 
// * */
//public class MonkeyTestingMain extends UISpecTestCase {
//
//	public final String mainClassName;
//	public final Class<?> mainClass;
//	public final String[] args;
//	
//	private int windowsPopTimeLimit = 50;
//	private int iterations = 10;
//	
//	public MonkeyTestingMain(String mainClassName, String[] args) {
//		Utils.checkNotNull(mainClassName);
//		Utils.checkNotNull(args);
//		this.mainClassName = mainClassName;
//		this.args = args;
//		try {
//		    mainClass = Class.forName(mainClassName);
//		} catch (Throwable e) {
//			throw new Error(e);
//		}
//		//set the time limit
//		UISpec4J.setWindowInterceptionTimeLimit(windowsPopTimeLimit);
//	}
//	
//	public Panel getFreshMainWindow() {
//		MonkeyTestingMain main = new MonkeyTestingMain(this.mainClassName, this.args);
//		main.setUpEnv();
//		return main.getMainWindow();
//	}
//	
//	public void setIterations(int iterations) {
//		Utils.checkTrue(iterations > 0, "Wrong iteration value: " + iterations);
//		this.iterations = iterations;
//	}
//	
//	public Collection<EventSequence> doMonkeyTesting() {
//		Collection<EventSequence> seqs = new LinkedList<EventSequence>();
//		for(int i = 0; i < this.iterations; i++) {
//			this.setUpEnv();
//			EventSequence newSeq = this.generateEventSequence();
//			seqs.add(newSeq);
//		}
//		return seqs;
//	}
//	
//	private void setUpEnv() {
//		setAdapter(new MainClassAdapter(this.mainClass, this.args));
//		try {
//	        super.setUp();
//		} catch (Throwable e) {
//			throw new Error(e);
//		}
//	}
//	
//	private EventSequence generateEventSequence() {
//		Utils.debugPrintln("--------------------");
//		
//		Panel mainWindow = getMainWindow();
//		Utils.debugPrintln(mainWindow.getDescription());
//		Utils.debugPrintln(System.identityHashCode(mainWindow));
//		MonkeyTester tester = new MonkeyTester(mainWindow);
//		EventSequence newSeq = tester.doTesting();
//		
//		return newSeq;
//	}
//	
//	public static void main(String[] args) {
//		//must init the environment
//		UISpec4J.init();
//		//start a tester
//		if(args.length == 0) {
//			System.err.println("args: main_class_name,  args");
//			System.exit(1);
//		}
//		String mainClassName = args[0];
//		String[] classArgs = new String[args.length - 1];
//		for(int i = 1; i < args.length; i++) {
//			classArgs[i-1] = args[i];
//		}
//		MonkeyTestingMain tester = new MonkeyTestingMain(mainClassName, classArgs);
//		Collection<EventSequence> seqs = tester.doMonkeyTesting();
//		int index = 1;
//		for(EventSequence seq : seqs) {
//			Utils.debugPrintln("The " + (index++) + "-th sequence: ");
//			Utils.debugPrintln(seq.toString());
//		}
//	}
//}
